package com.ruoyi.drone.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.drone.mapper.DroneTaskCategoryMapper;
import com.ruoyi.drone.domain.DroneTaskCategory;
import com.ruoyi.drone.service.IDroneTaskCategoryService;

/**
 * 任务分类Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-01-01
 */
@Service
public class DroneTaskCategoryServiceImpl implements IDroneTaskCategoryService 
{
    @Autowired
    private DroneTaskCategoryMapper droneTaskCategoryMapper;

    /**
     * 查询任务分类
     * 
     * @param categoryId 任务分类主键
     * @return 任务分类
     */
    @Override
    public DroneTaskCategory selectDroneTaskCategoryByCategoryId(Long categoryId)
    {
        return droneTaskCategoryMapper.selectDroneTaskCategoryByCategoryId(categoryId);
    }

    /**
     * 根据分类编码查询任务分类
     * 
     * @param categoryCode 分类编码
     * @return 任务分类
     */
    @Override
    public DroneTaskCategory selectDroneTaskCategoryByCategoryCode(String categoryCode)
    {
        return droneTaskCategoryMapper.selectDroneTaskCategoryByCategoryCode(categoryCode);
    }

    /**
     * 查询任务分类列表
     * 
     * @param droneTaskCategory 任务分类
     * @return 任务分类
     */
    @Override
    public List<DroneTaskCategory> selectDroneTaskCategoryList(DroneTaskCategory droneTaskCategory)
    {
        return droneTaskCategoryMapper.selectDroneTaskCategoryList(droneTaskCategory);
    }

    /**
     * 查询所有启用的任务分类
     * 
     * @return 任务分类集合
     */
    @Override
    public List<DroneTaskCategory> selectAllEnabledCategories()
    {
        return droneTaskCategoryMapper.selectAllEnabledCategories();
    }

    /**
     * 新增任务分类
     * 
     * @param droneTaskCategory 任务分类
     * @return 结果
     */
    @Override
    public int insertDroneTaskCategory(DroneTaskCategory droneTaskCategory)
    {
        // 设置默认状态为正常
        if (StringUtils.isEmpty(droneTaskCategory.getStatus())) {
            droneTaskCategory.setStatus("0");
        }
        
        // 设置默认排序
        if (droneTaskCategory.getSortOrder() == null) {
            droneTaskCategory.setSortOrder(0);
        }
        
        droneTaskCategory.setCreateTime(DateUtils.getNowDate());
        return droneTaskCategoryMapper.insertDroneTaskCategory(droneTaskCategory);
    }

    /**
     * 修改任务分类
     * 
     * @param droneTaskCategory 任务分类
     * @return 结果
     */
    @Override
    public int updateDroneTaskCategory(DroneTaskCategory droneTaskCategory)
    {
        droneTaskCategory.setUpdateTime(DateUtils.getNowDate());
        return droneTaskCategoryMapper.updateDroneTaskCategory(droneTaskCategory);
    }

    /**
     * 批量删除任务分类
     * 
     * @param categoryIds 需要删除的任务分类主键
     * @return 结果
     */
    @Override
    public int deleteDroneTaskCategoryByCategoryIds(Long[] categoryIds)
    {
        return droneTaskCategoryMapper.deleteDroneTaskCategoryByCategoryIds(categoryIds);
    }

    /**
     * 删除任务分类信息
     * 
     * @param categoryId 任务分类主键
     * @return 结果
     */
    @Override
    public int deleteDroneTaskCategoryByCategoryId(Long categoryId)
    {
        return droneTaskCategoryMapper.deleteDroneTaskCategoryByCategoryId(categoryId);
    }

    /**
     * 检查分类编码是否唯一
     * 
     * @param categoryCode 分类编码
     * @return 结果
     */
    @Override
    public boolean checkCategoryCodeUnique(String categoryCode)
    {
        return droneTaskCategoryMapper.checkCategoryCodeUnique(categoryCode) == 0;
    }
}
